package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.DeptBean;
import com.project.bean.EmployeeBean;
import com.project.mapper.IDeptMapper;
import com.project.mapper.IEmployeeMapper;
import com.project.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeptServiceImpl implements IDeptService {
    @Autowired
    private IDeptMapper mapper;
    @Autowired
    private IEmployeeMapper empMapper;

    @Override
    public List<DeptBean> findAll() {
        return mapper.findAll();
    }

    @Override
    public void add(DeptBean dept, List<EmployeeBean> emList) {
        mapper.insert(dept);
        empMapper.addMore(dept.getId(), emList);
    }

    @Override
    public void delCasede(Integer id) {
        mapper.delCasede(id);
    }

    @Override
    public void delSetNull(Integer id) {
        mapper.delSetNull(id);
    }

    @Override
    public DeptBean findById(Integer id) {
        DeptBean dept = mapper.selectById(id);
        QueryWrapper<EmployeeBean> qw = new QueryWrapper<>();
        qw.eq("fk_deptId", id);
        dept.setEmList(empMapper.selectList(qw));
        return dept;
    }
}
